int read = 0;
while (read < buf.length) {
buf[read++] = (byte) is.read();
}
int size = fromArray(buf);
int read = 0;
while (read < buf.length) {
int nextByte = is.read();
if (nextByte == -1) {
throw new ChromeCastException("Remote socket closed");
}
buf[read++] = (byte) nextByte;
}